﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
using System.Data.SqlClient;

namespace QLThuVien
{
    public partial class frTimKiemSach : Form
    {
        public frTimKiemSach()
        {
            InitializeComponent();
        }
        DataSet ds = new DataSet();
        CurrencyManager cm;
        public void load_group()
        {
            Truyxuatdulieu txdl = new Truyxuatdulieu();
            SqlDataReader dr = txdl.lay_reader("select TENLOAISACH from loaisach");
            while (dr.Read())
            {
                cblsach.Items.Add(dr[0].ToString());
            }
            KetNoi.closeconnect();

            KetNoi.setconnect();
            SqlDataReader dr1 = txdl.lay_reader("select HOTEN from tacgia");
            while (dr1.Read())
            {
                cbtg.Items.Add(dr1[0].ToString());
            }
            KetNoi.closeconnect();

            KetNoi.setconnect();
            SqlDataReader dr2 = txdl.lay_reader("select tennxb from NXB");
            while (dr2.Read())
            {
                cbnxb.Items.Add(dr2[0].ToString());
            }
            KetNoi.closeconnect();

            KetNoi.setconnect();
            SqlDataReader dr3 = txdl.lay_reader("select NGONNGU from ngonngu");
            while (dr3.Read())
            {
                cbnn.Items.Add(dr3[0].ToString());
            }
            KetNoi.closeconnect();

            KetNoi.setconnect();
            SqlDataReader dr4 = txdl.lay_reader("SELECT TENNCC FROM NHACUNGCAP");
            while (dr4.Read())
            {
                CBNCC.Items.Add(dr4[0].ToString());
            }
            KetNoi.closeconnect();
        }

        private void frTimKiemSach_Load(object sender, EventArgs e)
        {
            load_group();
        }

        private void bttimkiem_Click(object sender, EventArgs e)
        {
            LopTimKiem ltk = new LopTimKiem();
            ds = ltk.theodanhmuc(textBox1.Text, cbtg.Text, cblsach.Text, cbnn.Text, cbnxb.Text, CBNCC.Text);
            this.dataGridView1.DataSource = ds.Tables[0];
            cm = BindingContext[this.ds.Tables[0]] as CurrencyManager;
            label6.Text = cm.Count.ToString();   
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter) bttimkiem_Click(sender, e);
        }       


    }
}
